/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.songlin.houxin.admin.controller;

import com.pig4cloud.plugin.excel.annotation.RequestExcel;
import com.songlin.houxin.admin.api.dto.*;
import com.songlin.houxin.admin.api.vo.ActiveStatisticVO;
import com.songlin.houxin.admin.api.vo.BasePageVO;
import com.songlin.houxin.admin.api.vo.OrderVO;
import com.songlin.houxin.admin.api.vo.StatisticVO;
import com.songlin.houxin.admin.listeners.ExcelListener;
import com.songlin.houxin.admin.service.OrderService;
import com.songlin.houxin.common.core.util.R;
import com.songlin.pig.common.log.annotation.SysLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * 订单表
 *
 * @author pig code generator
 * @date 2022-03-06 08:13:05
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/order")
@Api(value = "order", tags = "订单表管理")
public class OrderController {
    private final OrderService orderService;

    /**
     * 订单导入接口
     *
     * @param voList        订单列表
     * @param bindingResult 绑定结果
     * @return
     */
    @ApiOperation(value = "激活管理中的明细导入", notes = "导入标签信息接口")
    @PostMapping("/importOrder")
    // @PreAuthorize("@pms.hasPermission('admin_order_add')")
    public R importOrder(@RequestExcel(readListener = ExcelListener.class) List<ETCDetailDTO> voList, BindingResult bindingResult) {

        return orderService.importOrder(voList, bindingResult);
    }

    @ApiOperation(value = "设备管理中的导入", notes = "导入标签信息接口")
    @PostMapping("/importDevice")
    // @PreAuthorize("@pms.hasPermission('admin_order_add')")
    public R importDevice(@RequestExcel(readListener = ExcelListener.class) List<ImportOrderDTO> voList, BindingResult bindingResult) {

        return orderService.importDevice(voList, bindingResult);
    }

    /**
     * @param dto 订单查询列表入参信息
     * @return
     */
    @PostMapping("/queryOrderList")
    // @PreAuthorize("@pms.hasPermission('admin_order_get')")
    public R<BasePageVO<OrderVO>> queryOrderList(@RequestBody OrderListDTO dto) {
        return R.ok(orderService.queryOrderList(dto));
    }


    /**
     * @return
     */
    @PostMapping("/updateOrder")
    public R<Void> updateOrder(@RequestBody OrderUpdateDTO dto) {
        orderService.updateOrder(dto);
        return R.ok();
    }

    /**
     * 批量删除订单信息
     *
     * @param dto 入参信息
     * @return
     */
    @ApiOperation(value = "批量删除订单信息", notes = "批量删除订单信息")
    @PostMapping("/deleteBatchOrder")
    public R<Void> deleteBatchOrder(@RequestBody OrderDeleteDTO dto) {
        orderService.deleteBatchOrder(dto);
        return R.ok();
    }

    /**
     * 新增渠道表
     *
     * @return R
     */
    @ApiOperation(value = "查询激活统计信息", notes = "查询激活统计信息")
    @SysLog("查询激活统计信息")
    @PostMapping(value = "/queryActiveStatisticInfo")
    // @PreAuthorize("@pms.hasPermission('admin_channel_add')" )
    public R<ActiveStatisticVO> queryActiveStatisticInfo(@RequestBody ActiveStatisticDTO dto) {
        return R.ok(orderService.queryActiveStatisticInfo(dto));
    }

    @ApiOperation(value = "条件查询激活统计信息", notes = "条件查询激活统计信息")
    @SysLog("条件查询激活统计信息")
    @PostMapping(value = "/queryStatisticInfo")
    // @PreAuthorize("@pms.hasPermission('admin_channel_add')" )
    public R<StatisticVO> queryStatisticInfo(@RequestBody ActiveStatisticDTO dto) {
        return R.ok(orderService.queryStatisticInfo(dto));
    }
}
